package controllers

import (
	"fmt"
	"gitee.com/ha666/golibs"
)

type BaseRPC int

type BaseRequest struct {
	Ver    int    //客户端版本号
	AppKey int    //客户端AppKey
	Time   int64  //当前时间戳
	V      int    //服务端版本号
	Sign   string //签名
}

func (base *BaseRequest) Verify() (int, string) {
	if base.Ver < 180201 {
		return 2051, "Ver太低"
	}
	if base.AppKey != 2018020116 {
		return 2053, "AppKey错误"
	}
	if base.Time < golibs.Unix()-180 || base.Time > golibs.Unix()+180 {
		return 2053, "Time错误"
	}
	if base.V != 1 {
		return 2055, "V错误"
	}
	if base.Sign != fmt.Sprintf("%x", golibs.Sha1([]byte(`fmt.Println(dog.name + " eat")`))) {
		return 2057, "Sign错误"
	}
	return 0, ""
}
